import Vue from 'vue'
let v = new Vue();
//对象转formdata格式
export function ObjToFormData(obj) { 
    let formData = new FormData();
	for (var i in obj) {
		//如果是数组
		if (isArray(obj[i])) {
		    obj[i].map(item => {
		        formData.append(i + '[]', item)
		    })
		} else if (obj[i] instanceof FileList) {
		    //filelist 文件类型的处理
		    for (var fileItem = 0; fileItem < obj[i].length; fileItem++) {
		         formData.append(i + '[]', obj[i].item(fileItem))
		    }
		} else {
			if(obj[i]==null){
				formData.append(i, "");
			}else{
				formData.append(i, obj[i]);
			}
		    
		}
		
	}
    return formData;
}
//判断是不是数组
function isArray(o){

return Object.prototype.toString.call(o)== '[object Array]';

}

const commonUtil={
   showMessage(code,message){
		 if("200"==code){
			v.$notify({
			  title: "成功",
			  message:message,
			  type: 'success'
			});
		 }else{
			v.$notify({
			  title: "失败",
			  message:message,
			  type: 'error'
			});
		 }
	 }
}

export default commonUtil